#ifndef TIANYU_PROXY_HEAD_
#define TIANYU_PROXY_HEAD_

#include <stdint.h>
#include "../../3rd/libjson/json.h"

namespace common
{
	class CProxyHead
	{
	public:
		CProxyHead()
		{
			clear();
		}
		void clear()
		{
			src_server_id = 0;
			src_server_type = 0;
			src_area_id = 0;
			dst_server_id = 0;
			dst_area_id = 0;
			dst_server_type = 0;
			msg_id = 0;
			session_id = 0;
			extend = 0;
			send_platform = 0;
			head_string.clear();
		}
		void Copy(const CProxyHead& head)
		{
			src_server_id = head.src_server_id;
			src_area_id = head.src_area_id;
			src_server_type = head.src_server_type;
			dst_server_id = head.dst_server_id;
			dst_area_id = head.dst_area_id;
			dst_server_type = head.dst_server_type;
			msg_id = head.msg_id;
			session_id = head.session_id;
			extend = head.extend;
			send_platform = head.send_platform;
		}
		std::string& GetHeadString()
		{
			Json::Value mjson;
			mjson["src_server_id"] = src_server_id;
			mjson["src_server_type"] = src_server_type;
			mjson["src_area_id"] = src_area_id;
			mjson["dst_server_id"] = dst_server_id;
			mjson["dst_server_type"] = dst_server_type;
			mjson["dst_area_id"] = dst_area_id;
			mjson["msg_id"] = msg_id;
			mjson["session_id"] = session_id;
			mjson["extend"] = extend;
			mjson["send_platform"] = send_platform;
			head_string = JsonWriter(mjson);
			return head_string;
		}
		bool ReadFromString(std::string& str)
		{
			Json::Value mjson;
			bool ret = JsonReader(str, mjson);
			if ( ret == false )
			{
				return ret;
			}
			src_server_id = mjson["src_server_id"].asUInt();
			src_server_type = mjson["src_server_type"].asUInt();
			src_area_id = mjson["src_area_id"].asUInt();
			dst_server_id = mjson["dst_server_id"].asUInt();
			dst_server_type = mjson["dst_server_type"].asUInt();
			dst_area_id = mjson["dst_area_id"].asUInt();
			msg_id = mjson["msg_id"].asUInt();
			session_id = mjson["session_id"].asInt();
			extend = mjson["extend"].asInt();
			send_platform = mjson["send_platform"].asInt();
			return true;
		}
	public:
		uint32_t src_server_id;	// 源游戏服务器ID,例如gameserver1，gameserver2类似的，现在没用，留着扩展
		uint32_t src_server_type;// 源服务器类型,game,map,chat,db
		uint32_t src_area_id;	// 源区服ID
		uint32_t dst_server_id;	// 目标游戏服务器ID
		uint32_t dst_server_type;//目标服务器类型
		uint32_t dst_area_id;	// 目标区服ID
		uint32_t msg_id;		//消息ID
		int32_t	session_id;		//session
		int32_t extend;			//扩展
		int32_t send_platform;	//1，发送到平台, 0发送到游戏服

		std::string head_string;
	};
}

#endif
